import Data.Char (digitToInt, isDigit)
import Control.Exception (catch)
import System.IO.Error (isEOFError)
import System.Exit (exitSuccess, exitFailure, exitWith, ExitCode (ExitFailure))

data MainState = Init | Zero | NonZero Int

step Init '0' = do 
    c <- getChar
    step Zero c
step Init c | c >= '1' && c <= '9' = do
    new_c <- getChar
    step (NonZero (digitToInt c)) new_c
step Init _ = do
    c <- getChar
    step Init c

step Zero c = 
    if c == '%' then putStr (show 0) else step Init c

step (NonZero val) '%' = putStr (show val)
step (NonZero val) c | isDigit c = do
    new_c <- getChar
    step (NonZero (val * 10 + digitToInt c)) new_c
step (NonZero val) c = step Init c

main = do
    c <- getChar
    catch (step Init c)
        (\e -> exitWith (ExitFailure (if isEOFError e then 1 else -1)))
